package com.tbit.uqbike.webmanager.util.http.rpc;

import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONUtil;
import com.tbit.common.constant.RpcConstants;
import com.tbit.common.constant.SystemConstant;
import com.tbit.uqbike.constant.OperaPswConstant;
import com.tbit.uqbike.constant.ResponseCode;
import com.tbit.uqbike.constant.ServiceUrlConstant;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.view.JsonResult;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 4.3.0
 * @since 2024/12/17 16:48
 */
@Slf4j
public class UQHttpMain {

    public static void batchUnOccupy(List<Integer> machineIds, Integer accountUserId) {
        // 远程调用运维端解除占用
        String url = OperaPswConstant.ACCOUNT_OPERA_MAIN_URL + RpcConstants.RPC_API_PREFIX + ServiceUrlConstant.MAIN_BATCH_UN_OCCUPY;

        if (log.isInfoEnabled()) {
            log.info("[UQHttpMain][batchUnOccupy][params: {}]", machineIds);
        }

        String resp = UQHttpUtil.sendJsonPost(url,
                JSONUtil.toJsonStr(machineIds),
                MapUtil.of(SystemConstant.ACCOUNT_USER_ID, String.valueOf(accountUserId)));

        if (log.isInfoEnabled()) {
            log.info("[UQHttpMain][batchUnOccupy][result: {}]", resp);
        }

        JsonResult jsonResult = JSONUtil.toBean(resp, JsonResult.class);

        if (ResponseCode.FAIL.equals(jsonResult.getRet())) {
            throw new BaseException(jsonResult.getMsg());
        }

    }

}
